<template>
  <div class="v-shop-felx-item">
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div class="v-shop-mall-container" v-for="(item, index) in shopCartListData" :key="index">
        <div class="v-shop-mall-name-box">
          <van-checkbox v-model="item.checked" @change="shopItemSelect(item)" ></van-checkbox>
          <span class="v-shop-mall-name">{{item.shopName}}</span>
        </div>
        <shopCartProductList v-for="(itemList, index) in item.shopCartListData" :shopCartListDataItem="itemList" :key="index"></shopCartProductList>
      </div>
    </van-pull-refresh>
  </div>
</template>

<script>
  import {
    SwipeCell,
    CellGroup,
    Cell,
    Card,
    Stepper,
    PullRefresh,
    Checkbox
  } from 'vant';
  import shopCartProductList from '../../../components/shopCartProductList.vue';
  import { mapGetters, mapActions } from 'vuex'
  export default {
    props:['shopCartListData'],
    data() {
      return {
        value: 1,
        imageURL: require('../../../assets/img/yifu.jpg'),
        isLoading: false
      }
    },
    components: {
      [SwipeCell.name]: SwipeCell,
      [CellGroup.name]: CellGroup,
      [Cell.name]: Cell,
      [Card.name]: Card,
      [Stepper.name]: Stepper,
      [PullRefresh.name]: PullRefresh,
      [Checkbox.name]:Checkbox,
      shopCartProductList

    },
    mounted() {
      
    },
    methods: {
      onRefresh() {
        setTimeout(() => {
          this.$toast('刷新成功');
          this.isLoading = false;
        }, 500);
      },
      shopItemSelect(item) {
        item.shopCartListData.forEach(ele => {
          ele.checked = item.checked;
          if (ele.checked) {
            this.addProductToCart(ele);
          }else{
            this.removeProductFromCart(ele);
          }
        });
      },
      ...mapActions('cart',{
        addProductToCart:'addProductToCart',
        removeProductFromCart:'removeProductFromCart'
      })
    }
  }
</script>

<style lang="scss">
  .v-shop-felx-item {
    .van-cell-swipe__right {
      color: #FFFFFF;
      font-size: 15px;
      width: 65px; //   height: 44px;
      display: inline-block;
      text-align: center; //   line-height: 44px;
      background-color: #F44;
      display: flex;
      align-items: center;
      justify-content: center;
    }           
    .van-pull-refresh{
        overflow: initial;
    }
    .van-cell-swipe{
      padding: 11px 15px;
    }
    .van-cell-swipe__right{
        right: -15px;
    }
    .v-shop-mall-container{
      .v-shop-mall-name-box{
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: 10px 15px;
        .v-shop-mall-name{
          font-size: 14px;
          margin-left: 10px;
        }
      }
    }
  }
</style>